// InheritExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

class Father
{
protected:
	char* name;
	int length;

public:
	 Father(char* str);

	 void show(){ cout<<"\nThe Name of the Father is "<<name<<endl;}

	 ~Father(){cout<<"\nDestructor active for Father.\n";}
};

Father::Father(char* str) 
{
	length = strlen(str);
	name = new char[length+1];

	strcpy(name,str);

	cout<<"\nConstructor is active for Father.\n";
}


class Child:public Father
{
protected:
     int age;
public:
     Child(char* str,int n);

     void show();

     ~Child(){cout<<"\nDestructor active for Child.\n";}
};

Child::Child(char* str,int n):Father(str)
{
	age = n;
	cout<<"\nConstructor is active for Child.\n";
}

void Child::show( )
{
	Father::show();
	cout<<"\nThe age for the child is:"<<age<<endl;
}




void _tmain()
{
	Father s1("Zhang"), *ptr1;
	cout<<"=================================="<<endl;
	
	Child  s2("Wang",20), *ptr2;	
	cout<<"=================================="<<endl;
	

	ptr1=&s1;
	ptr1->show();
	cout<<"=================================="<<endl;
	
	ptr1=&s2;	
	ptr1->show();
	cout<<"=================================="<<endl;	

	ptr2=&s2;	
	ptr2->show();
	cout<<"=================================="<<endl;

	getchar();
}


